﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NetCoreCMS.Common;
using NetCoreCMS.IServices;
using NetCoreCMS.Models;

namespace NetCoreCMS.Web.Areas.Web.Controllers
{
    public class TeamsController : UserController
    {
        public string action = string.Empty;
        public int page;         //当前页码
        public int totalcount;   //OUT数据总数
        public IActionResult Index(int id=0)
        {
            action = Request.Query["act"];
            if (string.IsNullOrEmpty(action))
                action = "direct";
            int.TryParse(Request.Query["page"], out page);
            page = page > 0 ? page : 1;
            ViewBag.action = action;

            if (action == "pass")
            {
                var puser = _users.GetModel(id);
                string pusername = "";
                if (puser != null)
                {
                    pusername = puser.user_name;
                }
                ViewBag.pusername = pusername;
            }

            if (id!= userModel.id)
            {
                id = userModel.id;
            }
            string strwhere = "where user_id>0 and pid=" + id;

            ViewBag.subusers = new List<Users>();

            var list = _users.GetList(page, 50, strwhere, "reg_time desc,id desc");
            totalcount = _users.RecordCount(strwhere);
            string pageUrl = Utils.CombUrlTxt("/Web/Teams/Index/"+id, "page={0}&act={1}", "__id__", action);
            ViewBag.pagelist = Utils.OutPageList(50, page, totalcount, pageUrl, 8);
            ViewBag.subusers = list;
            
            return View();
        }
    }
}